package com.yanqu.road.server.cmd.activity.dafuweng;

import com.yanqu.road.pb.monopoly.MonopolyProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.cross.battle.DaFuWengMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.server.protocol.GameProtocol;

import java.util.ArrayList;
import java.util.List;

@Cmd(code = Protocol.C_CROSS_DA_FU_WENG_PRE_HANDLE_ZAO_YAO_EVENT, desc = "跨服预处理造谣事件")
public class CrossPreHandleZaoYaoEventCmd extends CrossUnionCommand {

    int activityId;
    long serverId;
    long userId;
    String unionUid;
    private MonopolyProto.RollDiceRespMsg rollMsg;

    List<MonopolyProto.MonopolyUnionMsg> unionMsgList = new ArrayList<>();

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        MonopolyProto.CrossPreHandleZaoYaoEventReqMsg reqMsg = MonopolyProto.CrossPreHandleZaoYaoEventReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        serverId = reqMsg.getServerId();
        userId = reqMsg.getUserId();
        unionUid = reqMsg.getUnionUid();
        rollMsg = reqMsg.getRollMsg();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        unionMsgList = DaFuWengMgr.getRandomZaoYaoUnionMsg(activityId, unionUid);
    }

    @Override
    public void sendData() {
        MonopolyProto.CrossPreHandleZaoYaoEventRespMsg.Builder builder = MonopolyProto.CrossPreHandleZaoYaoEventRespMsg.newBuilder();
        builder.setActivityId(activityId);
        builder.setUserId(userId);
        builder.addAllUnionMsgList(unionMsgList);
        builder.setRollMsg(rollMsg);
        YanQuMessage yanQuMessage = YanQuMessageUtils.buildMessage(GameProtocol.S_DA_FU_WENG_GET_ZAO_YAO_UNION_FROM_CROSS, builder);
        MessageHelper.sendPacket(serverId, userId, yanQuMessage);
    }
}
